package com.gis507.mapreduce.done2;

import com.gis507.mapreduce.AISBean.AisClassifyBean;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.ArrayList;

/**
 * outPut K:AISClassifyBean  V:NullWritable
 */
public class AISClassReducer extends Reducer<Text, AisClassifyBean,AisClassifyBean, NullWritable> {

    @Override
    protected void reduce(Text key, Iterable<AisClassifyBean> values, Context context) throws IOException, InterruptedException {

        //defined a list to store aisdata
        ArrayList<AisClassifyBean> aisList = new ArrayList<>(1000);

        //itearable values moving data to aisList
        for (AisClassifyBean value : values) {

//            aisList.add(UtilsClass.getNewAisClassifyBean(value));
            context.write(value,NullWritable.get());

        }

//        //use lambda  format to sort the aisList,and return a new list
//        aisList.sort(AisClassifyBean::compareTo);
//
//        //iterator the aisList to write into context
//        for (AisClassifyBean ais : aisList) {
//
//            context.write(ais,NullWritable.get());
//
//        }
    }
}
